<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 平台活动
 * @author liub
 *
 */
class Activity extends CI_Controller {
	
	// 20150303 by liub 所有活动函数入口,优化原活动处理页面
	function detail($name){
		$this->load->view("activity/{$name}_activity");
	}
	
	
	/**跳转至活动页面
	 * 
	 * */
	function toactv_presell(){
		// 加载到活动页面
		$this->load->view("activity/presell_index");
	}
	
	function toactv_presell_detail(){
		// 加载到活动页面详情
		$this->load->view("activity/presell_detail");
	}
	
	function toactv_presell_notice($num){
		// 加载到活动页面通知页面
		$data['num'] = $num;
		$this->load->view("activity/presell_notice",$data);
	}
	
	function toactv_three_eight(){
		// 加载到元宵+三八节活动页面通知页面
		$this->load->model('Borrow_model');
		$vda['where']['id'] 		= array('37','38','39');
		$vda['where']['qtype'] = 'now';
		$vda['page_start'] = 0;
		$vda['page_size'] = 3;
		$vda['where']['srate'] = "8";
		$vdata = $this->Borrow_model->get_borrow_blist($vda);
		
		$vdata['borrow_bill_bank'] 			= $this->Borrow_model->arrays('borrow_bill_bank');//银行
		$vdata['borrow_style'] 				= $this->Borrow_model->arrays('borrow_style');//还款方式
		$vdata['borrow_work_time'] 			= $this->Borrow_model->arrays('borrow_work_time');//计息方式
		$vdata['borrow_fuse'] 				= $this->Borrow_model->arrays('borrow_fuse');//资金用途
		$vdata['borrow_good'] 				= $this->Borrow_model->arrays('borrow_good');
		
		$data['select'] = 1;
		$vdata['borrow1'] = $this->Borrow_model->get_borrow_obj('40', $data);
		$vdata['borrow2'] = $this->Borrow_model->get_borrow_obj('41', $data);

		$this->load->view("activity/three_eight",$vdata);
	}
	
	/**
	 * 上线活动1:
	 * */
	function on_line_first(){
		$ret = array ('msg' => '', 'sycDz' => '', 'num' => '', 'data' => array ('url' => '' ) );
		$phone = $this->input->post("phone");
		$realname 	= $this->input->post("realname");
		$captcha 	= $this->input->post('captcha');
		if ($captcha =="" ){
			$ret['msg'] = '请输入验证码';
			echo json_encode($ret);
			exit;
		}elseif ($captcha != $_SESSION['captcha']){
			$ret['msg'] = '您输入的验证码不正确';
			echo json_encode($ret);
			exit;
		}
		if(trim($realname) == "" || trim($realname)=="真实姓名"){
			$ret ['msg'] = '真实姓名不能为空' ;
			echo json_encode ( $ret );
			exit ();
		}
		if(trim($phone) == "" || !$this->myformcheck->isPhone ($phone)){
			$ret ['msg'] = '请填写有效的手机号码' ;
			echo json_encode ( $ret );
			exit ();
		}
		// 1.检测手机是否存在
		$this->load->model("Actpresellnum_model","presellnum");
		$row = $this->presellnum->get_num_by_phone($phone);
		if (isset ( $row ['presell_num'] ) && count($row) == 1) {
			$ret ['msg'] = '您已成功领取过预售卷，请妥善保存号码 '.$row ['presell_num'];
			echo json_encode ( $ret );
			exit ();
		}else{
			// 2.生成并保存预售卷号码
			$result = $this->add_presell($phone,$realname);
			if($result){
				$row = $this->presellnum->get_num_by_phone($phone);
				$ret ['data'] ['url'] = '/activity/toactv_presell_notice/'.$row ['presell_num'];
				$ret['num'] = $row ['presell_num'];
				echo json_encode ( $ret );
				exit ();
			}else{
				$ret ['msg'] = '获取预售卷失败';
				echo json_encode ( $ret );
				exit ();
			}
		}
	}
	
	function jihuoma(){
		//接收参数
		if($this->session->userdata('rsh_user') == false){//如果未登录就跳到登录页面
			$this->js->alert('请先登录');
			$this->js->go("/login.html");
			return;
		}
		$key = $this->input->post('key');
		$key = isset($key)?$key:"";
		$msg = "";
		if($key != ""){
			$content = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
						<keys>
							<key>
								<value>1511896X</value>
								<money>500</money>
								<begin_date>2015-01-16 00:00:00</begin_date>
								<end_date>2015-04-18 23:59:59</end_date>
							</key>
							<key>
								<value>9522489K</value>
								<money>1000</money>
								<begin_date>2015-01-16 00:00:00</begin_date>
								<end_date>2015-04-18 23:59:59</end_date>
							</key>
							<key>
								<value>5690560P</value>
								<money>888</money>
								<begin_date>2015-01-16 00:00:00</begin_date>
								<end_date>2015-02-28 23:59:59</end_date>
							</key>
						</keys>";
			$xml = simplexml_load_string($content);
			foreach($xml->children() as $child){  //获取XML对象里面的每一个子节点，也是一个类似于数组的对象
	            if($child->value == $key){
	               $begin_date = strtotime(date($child->begin_date));
	               $end_date= strtotime(date($child->end_date));
	               $now_date = time();
	               if($now_date >= $begin_date && $now_date <= $end_date){
	               		$user = $this->session->userdata('rsh_user');
			            //发放代金券
			            $this->load->model('Account_model', 'redaccount');
						$this->load->model('Redmanagement_model', 'redmanagement');
						$remark = "0118活动奖励";
						$res =  $this->redaccount->is_accountlog(array("user_id"=>$user['user_id'],"remark"=>$remark));
						if($res){
							$this->redmanagement->send_red($user['user_id'],16,$remark,$child->money);
							$msg = "领取奖励成功";
						}
						else $msg = "您已经领过奖励";
	               	}
	               	else $msg ="激活码过期";
	            }
	    	}
	    	if($msg == "") $msg = "激活码错误";
	    	$this->js->alert($msg);
	    	$this->js->go("/activity/jihuoma.html");
				return;
		}
		$data['sub_1'] = "活动领奖";
		$data['sub_1_href'] = "/activity/jihuoma.html";
		$data['sub_2'] = "激活码激活";
		$data['sub_2_href'] = "/activity/jihuoma.html";
		$this->load->view("activity/zhs_0118",$data);
	}
	
	
	private function add_presell($phone,$realname){
		$this->load->model("Actpresellnum_model","presellnum");
		$data = Array();
		$data['phone']			= $phone;
		$data['realname']		= $realname;
		$data['presell_num']	= $this->create_presell();//重复没问题
		$data['add_time']		= time();
		$data['lose_time']		= strtotime("2015-01-20 23:59:59");
		$data['addip']			= $this->js->get_ip();
		$data['fstatus']		= 0;
		$result = $this->presellnum->insert($data);
		return $result;
	}
	
	
	private function create_presell( $length = 6 ) {  
		// 密码字符集，可任意添加你需要的字符  
		$chars = '5102849673';  
		$presell = "";  
		for ( $i = 0; $i < $length; $i++ )  {  
			$presell .= $chars[ mt_rand(0, strlen($chars) - 1) ];  
		}  
		return $presell;  
	} 
	
		// 充多少送多少
	function rechargeActivity(){
		$this->load->view("activity/recharge7send");
	}
	
	
	// 领取红包
	function sendred(){
		$this->load->view("activity/redactivity");
	}
	
			function cpsAward(){
		// 加载到活动页面
		$this->load->view("activity/cps_award");
	}
	
		
	function investAward(){
		// 加载到活动页面
		$this->load->view("activity/invest_award");
	}
	
	function  holidayNotice(){
		// 加载到活动页面
		$this->load->view("activity/holidaynotice");
	}
	
		function  caifuAward(){
		// 加载到活动页面
		$this->load->view("activity/caifu_award");
	}
}
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 平台活动
 * @author liub
 *
 */
class Activity extends CI_Controller {
    
	// 20150303 by liub 所有活动函数入口,优化原活动处理页面
	function detail($name){
		$this->load->view("activity/{$name}_activity");
	}
	
	
	/**跳转至活动页面
	 * 
	 * */
	function toactv_presell(){
		// 加载到活动页面
		$this->load->view("activity/presell_index");
	}
	
	function toactv_presell_detail(){
		// 加载到活动页面详情
		$this->load->view("activity/presell_detail");
	}
	
	function toactv_presell_notice($num){
		// 加载到活动页面通知页面
		$data['num'] = $num;
		$this->load->view("activity/presell_notice",$data);
	}
	
	function toactv_three_eight(){
		// 加载到元宵+三八节活动页面通知页面
		$this->load->model('Borrow_model');
		$vda['where']['id'] 		= array('37','38','39');
		$vda['where']['qtype'] = 'now';
		$vda['page_start'] = 0;
		$vda['page_size'] = 3;
		$vda['where']['srate'] = "8";
		$vdata = $this->Borrow_model->get_borrow_blist($vda);
		
		$vdata['borrow_bill_bank'] 			= $this->Borrow_model->arrays('borrow_bill_bank');//银行
		$vdata['borrow_style'] 				= $this->Borrow_model->arrays('borrow_style');//还款方式
		$vdata['borrow_work_time'] 			= $this->Borrow_model->arrays('borrow_work_time');//计息方式
		$vdata['borrow_fuse'] 				= $this->Borrow_model->arrays('borrow_fuse');//资金用途
		$vdata['borrow_good'] 				= $this->Borrow_model->arrays('borrow_good');
		
		$data['select'] = 1;
		$vdata['borrow1'] = $this->Borrow_model->get_borrow_obj('40', $data);
		$vdata['borrow2'] = $this->Borrow_model->get_borrow_obj('41', $data);

		$this->load->view("activity/three_eight",$vdata);
	}
	
	/**
	 * 上线活动1:
	 * */
	function on_line_first(){
		$ret = array ('msg' => '', 'sycDz' => '', 'num' => '', 'data' => array ('url' => '' ) );
		$phone = $this->input->post("phone");
		$realname 	= $this->input->post("realname");
		$captcha 	= $this->input->post('captcha');
		if ($captcha =="" ){
			$ret['msg'] = '请输入验证码';
			echo json_encode($ret);
			exit;
		}elseif ($captcha != $_SESSION['captcha']){
			$ret['msg'] = '您输入的验证码不正确';
			echo json_encode($ret);
			exit;
		}
		if(trim($realname) == "" || trim($realname)=="真实姓名"){
			$ret ['msg'] = '真实姓名不能为空' ;
			echo json_encode ( $ret );
			exit ();
		}
		if(trim($phone) == "" || !$this->myformcheck->isPhone ($phone)){
			$ret ['msg'] = '请填写有效的手机号码' ;
			echo json_encode ( $ret );
			exit ();
		}
		// 1.检测手机是否存在
		$this->load->model("Actpresellnum_model","presellnum");
		$row = $this->presellnum->get_num_by_phone($phone);
		if (isset ( $row ['presell_num'] ) && count($row) == 1) {
			$ret ['msg'] = '您已成功领取过预售卷，请妥善保存号码 '.$row ['presell_num'];
			echo json_encode ( $ret );
			exit ();
		}else{
			// 2.生成并保存预售卷号码
			$result = $this->add_presell($phone,$realname);
			if($result){
				$row = $this->presellnum->get_num_by_phone($phone);
				$ret ['data'] ['url'] = '/activity/toactv_presell_notice/'.$row ['presell_num'];
				$ret['num'] = $row ['presell_num'];
				echo json_encode ( $ret );
				exit ();
			}else{
				$ret ['msg'] = '获取预售卷失败';
				echo json_encode ( $ret );
				exit ();
			}
		}
	}
	
	function jihuoma(){
		//接收参数
		if($this->session->userdata('rsh_user') == false){//如果未登录就跳到登录页面
			$this->js->alert('请先登录');
			$this->js->go("/login.html");
			return;
		}
		$key = $this->input->post('key');
		$key = isset($key)?$key:"";
		$msg = "";
		if($key != ""){
			$content = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
						<keys>
							<key>
								<value>1511896X</value>
								<money>500</money>
								<begin_date>2015-01-16 00:00:00</begin_date>
								<end_date>2015-04-18 23:59:59</end_date>
							</key>
							<key>
								<value>9522489K</value>
								<money>1000</money>
								<begin_date>2015-01-16 00:00:00</begin_date>
								<end_date>2015-04-18 23:59:59</end_date>
							</key>
							<key>
								<value>5690560P</value>
								<money>888</money>
								<begin_date>2015-01-16 00:00:00</begin_date>
								<end_date>2015-02-28 23:59:59</end_date>
							</key>
						</keys>";
			$xml = simplexml_load_string($content);
			foreach($xml->children() as $child){  //获取XML对象里面的每一个子节点，也是一个类似于数组的对象
	            if($child->value == $key){
	               $begin_date = strtotime(date($child->begin_date));
	               $end_date= strtotime(date($child->end_date));
	               $now_date = time();
	               if($now_date >= $begin_date && $now_date <= $end_date){
	               		$user = $this->session->userdata('rsh_user');
			            //发放代金券
			            $this->load->model('Account_model', 'redaccount');
						$this->load->model('Redmanagement_model', 'redmanagement');
						$remark = "0118活动奖励";
						$res =  $this->redaccount->is_accountlog(array("user_id"=>$user['user_id'],"remark"=>$remark));
						if($res){
							$this->redmanagement->send_red($user['user_id'],16,$remark,$child->money);
							$msg = "领取奖励成功";
						}
						else $msg = "您已经领过奖励";
	               	}
	               	else $msg ="激活码过期";
	            }
	    	}
	    	if($msg == "") $msg = "激活码错误";
	    	$this->js->alert($msg);
	    	$this->js->go("/activity/jihuoma.html");
				return;
		}
		$data['sub_1'] = "活动领奖";
		$data['sub_1_href'] = "/activity/jihuoma.html";
		$data['sub_2'] = "激活码激活";
		$data['sub_2_href'] = "/activity/jihuoma.html";
		$this->load->view("activity/zhs_0118",$data);
	}
	
	
	private function add_presell($phone,$realname){
		$this->load->model("Actpresellnum_model","presellnum");
		$data = Array();
		$data['phone']			= $phone;
		$data['realname']		= $realname;
		$data['presell_num']	= $this->create_presell();//重复没问题
		$data['add_time']		= time();
		$data['lose_time']		= strtotime("2015-01-20 23:59:59");
		$data['addip']			= $this->js->get_ip();
		$data['fstatus']		= 0;
		$result = $this->presellnum->insert($data);
		return $result;
	}
	
	
	private function create_presell( $length = 6 ) {  
		// 密码字符集，可任意添加你需要的字符  
		$chars = '5102849673';  
		$presell = "";  
		for ( $i = 0; $i < $length; $i++ )  {  
			$presell .= $chars[ mt_rand(0, strlen($chars) - 1) ];  
		}  
		return $presell;  
	} 
	
		// 充多少送多少
	function rechargeActivity(){
		$this->load->view("activity/recharge7send");
	}
	
	
	// 领取红包
	function sendred(){
		$this->load->view("activity/redactivity");
	}
	
			function cpsAward(){
		// 加载到活动页面
		$this->load->view("activity/cps_award");
	}
	
		
	function investAward(){
		// 加载到活动页面
		$this->load->view("activity/invest_award");
	}
	
	function  holidayNotice(){
		// 加载到活动页面
		$this->load->view("activity/holidaynotice");
	}
	
		function  caifuAward(){
		// 加载到活动页面
		$this->load->view("activity/caifu_award");
	}
}
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
